<?php

$f = $_GET['f'];
$w = @$_GET['w'];
$h = @$_GET['h'];

$base = dirname(__FILE__);
$path = $base . "/" . $f;
$ext  = strtolower(substr($f, strrpos($f, ".")+1));

$img = new Imagick($path);
$geo = $img->getImageGeometry();
$w0 = $geo['width'];
$h0 = $geo['height'];

if ($w || $h) {
	if ($w && $h) {
		$img->scaleimage($w, $h, true);
	} else {
		$img->scaleimage($w, $h);
	}
}

header("Content-Type: image/{$ext}");
echo $img;

?>